home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
4490
/
4490.xpi
/
components
/
scripts
/
pop3.js
< prev
next >
Wrap
Text File
|
2010-01-22
|
2KB
|
84 lines
/**********************************************************
POP3
**********************************************************/
var name="POP3";
var needServer=true;
function init(){
this.initStage=ST_DATA;
if(!this.server&&this.user.indexOf("@")!=-1)this.server="pop."+this.user.split("@")[1];
}
function processSocket(aData){
if(aData.indexOf("+OK")==0){
if(!this.process(null,aData))++this.stage;
}else{
this.onError();
}
}
function process(aHttpChannel, aData) {
switch(this.stage){
case ST_DATA:
var ar=this.server.split(":");
var port=ar[1]?ar[1]:995;
this.sock=new SocketReader(this,ar[0],port,port==995);
return false;
case ST_DATA+1:
var user;
if(this.user.indexOf("|")!=-1)user=this.user.split("|")[0];
else user=this.user.split("@")[0];
this.send("USER "+user);
return false;
case ST_DATA+2:
this.send("PASS "+this.password);
return false;
case ST_DATA+3:
this.send("STAT");
return false;
case ST_DATA+4:
var fnd=aData.match(/\+OK\s(\d+)/);
if(fnd){
var cnt=this.main.wuGetVal(this.id,this.user,0);
cnt=cnt?parseInt(cnt):0;
var num=parseInt(fnd[1]);
this.newData=num;
if(num>=cnt){
this.mailCount=num-cnt;
}else{
this.main.wuSetVal(this.id,this.user,0,num);
this.mailCount=0;
}
this.mailData=this.getData(aData);
this.mailData.desc=this.getDesc();
}
this.send("QUIT");
return false;
case ST_DATA+5:
this.sock.close();
if(this.mailCount<0)this.reset();
else this.stage=ST_DATA;
this.main.setState(nsIWebMailNotifier.ST_MAILDATA,this.ind);
return true;
}
this.onError();
return true;
}
function stop(){
if(this.sock)this.sock.close();
}
function send(cmd){
this.sock.write(cmd+"\r\n");
}
function calcCount(){
return this.mailCount;
}
function getMailURL(){
this.main.wuSetVal(this.id,this.user,0,this.newData);
delete this.newData;
this.mailCount=0;
if(!this.main.newMailsOnly){
this.mailData.desc=this.getDesc();
this.main.setState(nsIWebMailNotifier.ST_MAILDATA,this.ind);
}
return null;
}